package com.example.demo;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class FourthActivity extends AppCompatActivity {
   private WebView myWebView_1;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fourth);

        myWebView_1 = findViewById(R.id.myWebView_1);

        myWebView_1.loadUrl("http://www.baidu.com");

        myWebView_1.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                myWebView_1.loadUrl(url);
                return true;
            }//确保页面在程序内显示，而不是调到外部浏览器链接

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                Log.e("FourthActivity.this","开始加载");
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                Log.e("FourthActivity.this","结束加载");
                super.onPageFinished(view, url);
            }
        });
    }
    public void onBackPressed() {

        if (myWebView_1.canGoBack()) {
            myWebView_1.goBack();
        } else {
            super.onBackPressed();
        }
    }
}
